import { Injectable } from '@angular/core';
import { SingerDetail, Singer } from '@services/data-types/common.type';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable, forkJoin } from 'rxjs';
import { SingerService } from '@services/singer.service';
import { first } from 'rxjs/operators';

type SingerDetailModel = [SingerDetail, Singer[]];

@Injectable()
export class SingerResolveService implements Resolve<SingerDetailModel> {
  constructor(private singerService: SingerService) {}
  resolve(route: ActivatedRouteSnapshot): Observable<SingerDetailModel> {
    const id = route.paramMap.get('id');
    return forkJoin(
     this.singerService.getSingerDetail(id),
     this.singerService.getSimiSinger(id)
    ).pipe(first());
  }
}
